home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2551 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  44 lines

  1. Path: sasabe.acms.arizona.edu!jwhite
  2. From: Kenton White <jwhite@sasabe.acms.arizona.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Passing a pointer to a class function
  5. Date: Wed, 17 Jan 1996 16:54:03 -0700
  6. Organization: The University of Arizona
  7. Message-ID: <Pine.SUN.3.91.960117160141.13519A-100000@sasabe.acms.arizona.edu>
  8. NNTP-Posting-Host: sasabe.acms.arizona.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12.  
  13. I have a library subroutine that takes as an argument a pointer to a 
  14. function.  I want to pass instead a pointer to a class function.  The 
  15. class looks like this:
  16.  
  17. class device {
  18.  
  19. // ...
  20.  
  21. public:
  22.  
  23. //...
  24. void derivs(float, complex*, complex*)
  25. };
  26.  
  27. The subroutine expects a pointer to a function like this:
  28.  
  29. rk(void (*)(float, void*, void*))
  30.  
  31. I pass the class function like this:
  32.  
  33. device laser;
  34. rk(void (*)(float,void*, void*))laser.derivs;
  35.  
  36. When it compiles it gives me an anachronism warning and then crashes 
  37. with a memory fault on execution.  I have developed a temporary fix by 
  38. declaring a seperate function in the main program called derivs that 
  39. calls the class function derivs.  This works but is silly.  Is there a 
  40. way to pass the pointer to the class function?
  41.  
  42. Kenton
  43.  
  44.